<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="org.wso2.carbon.registry.custom.dia.ui.beans.EndpointBean" %>
<%@ page import="org.wso2.carbon.registry.custom.dia.ui.utils.GetDocumentUtil" %>
<%@ page import="org.wso2.carbon.registry.common.utils.RegistryUtil" %>
<%@ page import="org.wso2.carbon.registry.common.ui.UIException" %>
<%@ page import="org.wso2.carbon.registry.custom.dia.ui.clients.TopicServiceClient" %>
<%@ page import="org.wso2.carbon.registry.custom.dia.ui.beans.xsd.TagBean" %>
<%@ page import="org.wso2.carbon.registry.custom.dia.ui.beans.xsd.AssociationBean" %>

<%
    String cPath = RegistryUtil.getPath(request);
    EndpointBean bean;
    String tagString="";
    String title="";
    String summary="";
    String externalLink="";
    String productName="";
    String productRelease="";
    String carbonPlatform="";
    String jdkPlatform="";

    TopicServiceClient client;
    try {
        GetDocumentUtil getDocumentUtil = new GetDocumentUtil(config, session);
        bean = getDocumentUtil.getEndpointBean(cPath, config, session);
      //  AssociationBean[] assoBeans = getDocumentUtil.getAllAssociations(cPath);
      System.out.println(cPath);
      client = new TopicServiceClient(config, session);
       // System.out.println(assoBeans[0].getDestinationPath());
         //getDocumentUtil.getAllAssociations(cPath);
 
        TagBean[] tagBeans = client.getTags(cPath);
        int index=0;
        if(tagBeans != null){
            for(TagBean tagBean:tagBeans){
                tagString +="<a href=\"../search/search.jsp?criteria="+
                        tagBean.getTagName() + "&searchType=Tag\">" +
                        tagBean.getTagName() + "</a>, ";
/*
               tagString +=  "<a onmouseover=\"showDelx('"+ index +
                   "')\" class=\"cloud-x1\" href=\"../search/search.jsp?searchType=tag&amp;criteria="+
                   tagBean.getTagName()+"\"> "+tagBean.getTagName()+" </a>" +
                   "<a title=\"Delete\" style=\"\" id=\"delx"+index+"\" onclick=\"delTagx('"+tagBean.getTagName()+"','"+cPath+"')\" class=\"closeButton registryWriteOperation\"> x </a>&nbsp;&nbsp;";
*/
                index++;
            }
        }
        title = bean.getTitle();
        summary = bean.getSummary();
        externalLink = bean.getExternalLink();

        productName=bean.getProductName();
        productRelease=bean.getProductRelease();
        carbonPlatform=bean.getCarbonPlatform();
        jdkPlatform=bean.getJdkPlatform();

        if(productName == null) productName="";
        if(productRelease == null) productRelease="";
        if(carbonPlatform == null) carbonPlatform="";
        if(jdkPlatform == null) jdkPlatform="";
    } catch (UIException e) {
        System.out.println("Error in retrieving details.");
        %>Error occured while retrieving Documentation details<%
        return;
    }
%>

<!--
<script type="text/javascript">
    function showDelx(id){
        
        var wanted = $('delx'+id);
	var all = $('tagList1').getElementsByTagName("*");
	for(var i=0;i<all.length;i++){
		if(YAHOO.util.Dom.hasClass(all[i],'closeButton')){
			all[i].style.display="none";
		}
	}
	wanted.style.display = "";
    }

    function delTagx(tag,path){
        CARBON.showConfirmationDialog(org_wso2_carbon_registry_info_ui_jsi18n["are.you.sure.you.want.to.delete.this.tag"], function() {
	        new Ajax.Request('../info/tag-delete-ajaxprocessor.jsp', {
	            method: 'post',
	            parameters: {path: path, tag: tag},
	            onSuccess: function(transport) {
                    $('tagList1').innerHTML = transport.responseText;
                    },

                    onFailure: function(transport) {
                        showRegistryError(transport.responseText);
                    }
	        });

	    }, null);
    }
</script>
-->
<br/>



                    <h1><%=title%></h1><br>
                    <div>
                        <h3>Summary</h3>
                        <div>
                            <%=summary%><br><br>
                        </div>
                    </div>
                    <div>
                        <h4>External Link: </h4> <a target="_blank" href="<%=externalLink%>"><%=externalLink%></a><br>
                    </div>
                    <div>
                        <h3>Applies To:</h3>
                        <ul>
                        <li><p><a href="../search/search.jsp?region=region3&amp;item=registry_search_menu&amp;searchType=tag&amp;criteria=<%=productName%>">
                           <%=productName%></a></p>
                        </li>
                        <li><p><a href="../search/search.jsp?region=region3&amp;item=registry_search_menu&amp;searchType=tag&amp;criteria=<%=productRelease%>">
                            <%=productRelease%></a></p>
                        </li>
                        </ul>
                    </div>
                    <div>
                        <h3>Environment</h3>
                        <ul>
                        <li><p>Carbon Platform:  <%=carbonPlatform%></p></li>
                        <li><p>JDK Platform:  <%=jdkPlatform%></p></li>
                        </ul>
                    </div>
                    <div>
                        <h3>Tags: </h3><%=tagString%><br>
                    </div>
                    <div>
                        <h3>Related Documentations: </h3>
                        <ul>
                        <%
                            AssociationBean[] assoBeans =  client.getAllAssociations(cPath);
                            for(AssociationBean assoBean:assoBeans){
                                String dPath = assoBean.getDestinationPath();
                        %>
                        <li><p><a href="../resources/resource.jsp?path=<%=dPath%>">
                            <%=dPath%></a></p>
                        </li>
                        <%
                            }
                        %>
                        </ul>
                        <br>
                    </div>

                    <a href="dia_edit_ajaxprocessor.jsp?path=<%=cPath%>">Edit Document Details</a>

                    <br/>